home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_3 / phoonsrc / amiga.c next >
C/C++ Source or Header  |  1994-02-23  |  5KB  |  199 lines

  1. /*
  2.  *  amiga.c
  3.  *
  4.  *  Author: Tomi Ollila <too@cs.hut.fi>
  5.  *
  6.  *  Created: Sun Jul 05 15:30:58 1992 too
  7.  *  Last modified: Thu Feb 24 11:55:00 1994 too
  8.  *
  9.  */
  10.  
  11. asm(".text; jmp _start");
  12.  
  13. #include <exec/types.h>
  14. #include <intuition/intuition.h>
  15. #include <libraries/locale.h>
  16.  
  17. #define IFFL_CloseIFF    IFFL_NO1
  18. #define IFFL_DecodePic    IFFL_NO2
  19. #define IFFL_GetBMHD    IFFL_NO3
  20. #define IFFL_OpenIFF    IFFL_NO4
  21. #define IFFL_SaveBitMap IFFL_NO5
  22. #include "iff.h"
  23. #undef IFFL_CloseIFF
  24. #undef IFFL_DecodePic
  25. #undef IFFL_GetBMHD
  26. #undef IFFL_OpenIFF
  27. #undef IFFL_SaveBitMap
  28.  
  29. #include "inlines_other.h"
  30. #include "inline_iff.h"
  31.  
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include "amiga.h"
  35.  
  36. #ifndef NULL
  37. #define NULL 0
  38. #endif
  39.  
  40. static const char ver[] = "$VER: phoon 2.1 (24.2.1994)";
  41.  
  42. struct ExecBase *    SysBase = NULL;
  43. struct DosLibrary *    DOSBase = NULL;
  44.      
  45. struct IntuitionBase *    IntuitionBase = NULL;
  46. struct GfxBase *    GfxBase = NULL;
  47. struct Library *    IFFBase = NULL;
  48.  
  49. struct Library *    MathIeeeDoubBasBase = NULL;
  50. struct Library *    MathIeeeDoubTransBase = NULL;
  51.  
  52. struct Library *    LocaleBase = NULL;
  53.  
  54. #define SL(a) ((struct Library **)a)
  55.  
  56. struct {
  57.   struct Library **    base;
  58.   char *        name;
  59.   int            version;
  60. } libtable[] = {
  61.   { SL(&DOSBase),        "dos.library",             36 },
  62.   { SL(&IntuitionBase),        "intuition.library",        36 },
  63.   { SL(&GfxBase),        "graphics.library",        36 },
  64.   { SL(&IFFBase),        "iff.library",            23 },
  65.   { SL(&MathIeeeDoubBasBase),    "mathieeedoubbas.library",    36 },
  66.   { SL(&MathIeeeDoubTransBase),    "mathieeedoubtrans.library",    36 },
  67.   { NULL }
  68. };
  69.  
  70. struct RDArgs * rdargs = NULL;
  71.  
  72. WORD gmtoffset = 32767;
  73.  
  74. BOOL am_OpenLibraries()
  75. {
  76.   int i;
  77.   struct Library ** lib;
  78.   struct Locale * locale;
  79.   
  80.   SysBase = *(struct ExecBase **)4;
  81.  
  82.   for (i = 0; (lib = libtable[i].base); i++) {
  83.     if ((*lib = OpenLibrary(libtable[i].name, libtable[i].version)) == NULL) {
  84.       Printf("Could not open %s\n", libtable[i].name);
  85.       return FALSE;
  86.     }
  87.   }
  88.  
  89.   if ((LocaleBase = OpenLibrary("locale.library", 38)) != NULL) {
  90.     if ((locale = OpenLocale(NULL)) != NULL) {
  91.       gmtoffset = locale->loc_GMTOffset;
  92.       CloseLocale(locale);
  93.     }
  94.     CloseLibrary(LocaleBase);
  95.   }
  96.   
  97.   if ((rdargs = ReadArgs(TEMPLATE, args, NULL)) == NULL) {
  98.     Printf(usage);
  99.     return FALSE;
  100.   }
  101.   return TRUE;
  102. }
  103.  
  104. int am_CloseLibraries(int retval)
  105. {
  106.   int i;
  107.   struct Library ** lib;
  108.  
  109.   if (rdargs)
  110.     FreeArgs(rdargs);
  111.   
  112.   for (i = 0; (lib = libtable[i].base); i++)
  113.     if (*lib)
  114.       CloseLibrary(*lib);
  115.   return retval;
  116. }
  117.  
  118. BOOL am_GetScreenSize(int * w, int * h)
  119. {
  120.   struct Screen screen;
  121.  
  122.   if (GetScreenData((APTR)&screen, sizeof(struct Screen),
  123.             WBENCHSCREEN, NULL) == NULL) {
  124.     Printf("Could not figure out screensize.\n");
  125.     return FALSE;
  126.   }
  127.   *w = screen.Width;
  128.   *h = screen.Height;
  129.   return TRUE;
  130. }
  131.  
  132. char * am_LoadFullmoon(int * w,int * h, char * filename)
  133. {
  134.   PLANEPTR        plane = NULL;
  135.   IFFL_HANDLE        iffhandle;
  136.   struct BitMap     bitmap;
  137.   struct IFFL_BMHD *    bmhd;
  138.   int             size;
  139.  
  140.   if (filename == NULL)
  141.     filename = "fullmoon.ilbm\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  142.                             "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  143.  
  144.   if ((iffhandle = IFFL_OpenIFF(filename, IFFL_MODE_READ)) == NULL) {
  145.     Printf("Error: Could not open %s for reading as fullmoon picture\n",
  146.        filename);
  147.     return NULL;
  148.   }
  149.   if ((bmhd = IFFL_GetBMHD(iffhandle)) == NULL) {
  150.     Printf("Error: no BMHD chunk in %s \n", filename);
  151.     goto exit;
  152.   }
  153.   *w = (int)bmhd->w; *h = (int)bmhd->h;
  154.   size = BitmapSize(bmhd->w, bmhd->h);
  155.  
  156.   if ((plane = (PLANEPTR)AllocVec(size, 0)) == NULL) {
  157.     Printf("Out of memory\n");
  158.     goto exit;
  159.   }
  160.   InitBitMap(&bitmap, 1, bmhd->w, bmhd->h);
  161.   bitmap.Planes[0] = plane;
  162.  
  163.   if (IFFL_DecodePic(iffhandle, &bitmap) == FALSE) {
  164.     Printf("Error: Could not decode IFF picture\n");
  165.     FreeVec(plane);
  166.     plane = NULL;
  167.   }
  168.  exit:
  169.   IFFL_CloseIFF(iffhandle);
  170.   return (char *)plane;
  171. }
  172.  
  173. static UWORD colortable[] = {0xaaa, 0x000, 0xfff, 0x68b};
  174.  
  175. void am_MakeIFFile(int w, int h, char * bits, int reverseflag)
  176. {
  177.   struct BitMap bitmap;
  178.   LONG        size;
  179.   ULONG     *plane1, *plane0;
  180.   int        i;
  181.  
  182.   InitBitMap(&bitmap, 2, w, h);
  183.   size = BitmapSize(w, h);
  184.   plane0 = (ULONG *)bits;
  185.  
  186.   if ((plane1 = (ULONG *)AllocMem(size, 0)) == NULL) {
  187.     Printf("Out of memory\n");
  188.     return;
  189.   }
  190.   bitmap.Planes[reverseflag] = (PLANEPTR)plane1;
  191.   bitmap.Planes[(reverseflag + 1) & 1] = (PLANEPTR)plane0;
  192.  
  193.   for (i = 0; i < size >> 2; i++)
  194.     plane1[i] = plane0[i] ^ 0xffffffff;
  195.  
  196.   (void)IFFL_SaveBitMap("RAM:phoon.ilbm", &bitmap, colortable, 0);
  197.   FreeMem(plane1, size);
  198. }
  199.